{php include wl_template('common/header');}
<!-- page 容器 -->
<div class="page">
  <!-- 标题栏 -->
  <header class="bar bar-nav">
    <a class="icon icon-me pull-left open-panel"></a>
    <h1 class="title">绑定柜子与管理员</h1>
  </header>
123
  <!-- 这里是页面内容区 -->
  <div class="content" name="main">
    <div class="content-block">设备信息ID：{$info_id}</div>
    {if $needsetup == true}
    <div class="content-block">设备名称<span style="color: red;">* </span>： <input type="text" name="device_name" placeholder="请确保唯一性"></div>  
    <div class="content-block">柜门数量<span style="color: red;">* </span>：<input type="text" name="door_num" placeholder="设置柜门总数量"></div>        
    {else}
    <div class="content-block">设备名称<span style="color: red;">* </span>：{$device_name}</div>  
    <div class="content-block">柜门总数量<span style="color: red;">* </span>：{$door_num}</div>            
    {/if}
    {if $already_name == true}
        <div class="content-block">姓名<span style="color: red;">* </span>：{$admin_name}</div>
    {else}
        <div class="content-block">姓名<span style="color: red;">* </span>：<input type="text" name="name" placeholder="您的姓名"></div>
    {/if}
    <div class="content-block"> <input type="submit" value="绑定" openid="{$_W['openid']}"/></div>
  </div>
</div>

<!-- popup, panel 等放在这里 -->
<div class="panel-overlay"></div>
<script type="text/javascript">
function submit_check()
{
    if($("input[name='device_name']").length > 0){
        var device_name = $("input[name='device_name']").val();
        if(device_name ==''){
            alert("请输入设备名称，方便管理！");	
          return false;    
        }    
    }

    if($("input[name='door_num']").length > 0){
        var door_num = $("input[name='door_num']").val();
        var re = /^[1-9][0-9]*$/;
        if(!re.test(door_num)){
            alert("请输入正确的柜门总数量，方便管理！");	
          return false;    
        }     
    }
    if($("input[name='name']").length > 0){
         if(document.getElementsByName("name")[0].value.length ==0 )
        {
            alert("请输入您的姓名！");	
          return false;
        }
         else
         {
             var name = document.getElementsByName("name")[0].value;
             var re = /^[\u2E80-\u9FFF]+$/;
            if(!re.test(name)) {
                alert('姓名请输入汉字');
                //window.location.href=window.location.href;
                return false;
            } 
        return true;
        }    
    }

    
    return true;
}
	$(function(){
        $('input:submit').click(function() {
        console.log(1111);
            if(submit_check()){              
                var info_id = "{php echo $info_id}";
                var openid = $(this).attr('openid');
                if($("input[name='device_name']").length > 0)
                    var device_name = $("input[name='device_name']").val();
                else
                    var device_name = "{php echo $device_name}";
                if($("input[name='door_num']").length > 0)
                    var door_num = $("input[name='door_num']").val();
                else
                    var door_num = "{php echo $door_num}";
                if($("input[name='name']").length > 0)
                    var name = $("input[name='name']").val();
                else
                    var name = "{php echo $admin_name}";
                //alert(name);
                $.post("{php echo app_url('scangenerate/scan/cabinet_admin_button');}", { info_id : info_id , openid : openid , name : name ,device_name : device_name ,door_num : door_num},function(data){
                    //alert(data);
                    window.location="{php echo app_url('scangenerate/scan/prompt');}&prompt="+data;   
                }); 
                              
            }           
		});

        
	});

</script>

{php include wl_template('common/footer');}
	